﻿@page
@{ Layout = "_Layout"; }
@section Styles{
  <style>
    .commands div { display: inline-block; width: auto; }
    .el-upload, .el-upload-dragger { display: inline-block; width: auto; }
  </style>
}

<el-container>
  <el-aside width="100px">
    <el-tabs v-model="fileType" tab-position="left" style="height: 100%;" v-on:tab-click="btnNavClick">
      <el-tab-pane label="样式文件" name="css"></el-tab-pane>
      <el-tab-pane label="脚本文件" name="js"></el-tab-pane>
      <el-tab-pane label="图片文件" name="images"></el-tab-pane>
    </el-tabs>
  </el-aside>

  <el-container>
    <el-main>
      <el-row>
        <el-col :span="12">
          <el-form v-on:submit.native.prevent :inline="true" size="small">
            <el-form-item label="文件夹路径" prop="directoryPaths">
              <el-cascader
                v-model="directoryPaths"
                :options="directories"
                :props="{ multiple: true, checkStrictly: true }"
                filterable
                v-on:change="reload"
                placeholder="请选择文件夹路径"></el-cascader>
            </el-form-item>
            <el-form-item label="文件夹路径/文件名">
              <el-input
                v-model="keyword"
                v-on:change="reload"
                placeholder="请输入文件夹路径名称或文件名称"
              ></el-input>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col class="commands" align="right" :span="12">
          <template v-if="fileType == 'css'">
            <el-button size="small" type="primary" v-on:click="btnAddClick('css')">
              <i class="el-icon-circle-plus-outline"></i>
              新增样式文件
            </el-button>
            <el-upload
              :action="getUploadUrl()"
              :headers="{Authorization: 'Bearer ' + $token}"
              :before-upload="uploadBefore"
              :on-progress="uploadProgress"
              :on-success="uploadSuccess"
              :on-error="uploadError"
              :multiple="true"
              :show-file-list="false">
              <el-button size="small" type="primary">
                <i class="el-icon-upload"></i>
                上传样式文件
              </el-button>
          </template>
          <template v-if="fileType == 'js'">
            <el-button size="small" type="primary" v-on:click="btnAddClick('js')">
              <i class="el-icon-circle-plus-outline"></i>
              新增脚本文件
            </el-button>
            <el-upload
              :action="getUploadUrl()"
              :headers="{Authorization: 'Bearer ' + $token}"
              :before-upload="uploadBefore"
              :on-progress="uploadProgress"
              :on-success="uploadSuccess"
              :on-error="uploadError"
              :multiple="true"
              :show-file-list="false">
              <el-button size="small" type="primary">
                <i class="el-icon-upload"></i>
                上传脚本文件
              </el-button>
            </el-upload>
          </template>
          <template v-if="fileType == 'images'">
            <el-upload
              :action="getUploadUrl()"
              :headers="{Authorization: 'Bearer ' + $token}"
              :before-upload="uploadBefore"
              :on-progress="uploadProgress"
              :on-success="uploadSuccess"
              :on-error="uploadError"
              :multiple="true"
              :show-file-list="false">
              <el-button size="small" type="primary">
                <i class="el-icon-upload"></i>
                上传图片文件
              </el-button>
            </el-upload>
          </template>
          
          <el-button size="small" type="primary" v-on:click="btnConfigClick">
            <i class="el-icon-setting"></i> 文件夹路径设置
          </el-button>
        </el-col>
      </el-row>
      

      <el-table :data="files" style="width: 100%">
        <el-table-column label="资源文件">
          <template slot-scope="scope">
            <el-link
              :underline="false"
              v-on:click="btnEditClick(scope.row)"
              type="primary">
              {{ scope.row.directoryPath + '/' + scope.row.fileName }}
            </el-link>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="130">
          <template slot-scope="scope">
            <el-link
              :underline="false"
              :href="getPageUrl(scope.row.directoryPath + '/' + scope.row.fileName)"
              target="_blank"
              type="primary">
              查看
            </el-link>
            <el-link
              v-if="fileType == 'css' || fileType == 'js'"
              :underline="false"
              v-on:click="btnEditClick(scope.row)"
              type="primary">
              编辑
            </el-link>
            <el-link
              :underline="false"
              type="danger"
              v-on:click="btnDeleteClick(scope.row)">
              删除
            </el-link>
          </template>
        </el-table-column>
      </el-table>

    </el-main>
  </el-container>
</el-container>

<el-drawer
  id="configForm"
  v-if="configForm"
  title="文件夹路径设置"
  ref="configPanel"
  :visible.sync="configPanel"
  destroy-on-close
  direction="rtl"
  size="50%">
  <div class="drawer__content">
    <el-form v-on:submit.native.prevent ref="configForm" :model="configForm" label-width="150px" :rules="{
      cssDir: [
        { required: true, message: '请输入样式文件文件夹路径', trigger: 'blur' }
      ],
      jsDir: [
        { required: true, message: '请输入脚本文件文件夹路径', trigger: 'blur' }
      ],
      imagesDir: [
        { required: true, message: '请输入图片文件文件夹路径', trigger: 'blur' }
      ]
    }">
    <el-form-item label="样式文件文件夹路径" prop="cssDir">
      <el-input v-model="configForm.cssDir" placeholder="请输入样式文件文件夹路径"></el-input>
    </el-form-item>
    <el-form-item label="脚本文件文件夹路径" prop="jsDir">
      <el-input v-model="configForm.jsDir" placeholder="请输入脚本文件文件夹路径"></el-input>
    </el-form-item>
    <el-form-item label="图片文件文件夹路径" prop="imagesDir">
      <el-input v-model="configForm.imagesDir" placeholder="请输入图片文件文件夹路径"></el-input>
    </el-form-item>

    <el-divider></el-divider>
    <div class="drawer__footer">
      <el-button type="primary" v-on:click="btnConfigSubmitClick" size="small">确 定</el-button>
      <el-button size="small" v-on:click="btnConfigCancelClick">取 消</el-button>
    </div>
  </el-form>
  </div>
</el-drawer>

@section Scripts{
<script src="/sitefiles/assets/js/admin/cms/templatesAssets.js" type="text/javascript"></script>
}
